package com.qumoyugo.springframework.aop;

import com.qumoyugo.springframework.aop.framework.AopProxy;
import com.qumoyugo.springframework.aop.framework.Cglib2AopProxy;
import com.qumoyugo.springframework.aop.framework.JdkDynamicAopProxy;

/**
 * @author Cedric
 * @date 2021/11/30 16:06
 * @description 代理工厂
 */
public class ProxyFactory implements AopProxy {
    private AdvisedSupport advised;

    public ProxyFactory(AdvisedSupport advised) {
        this.advised = advised;
    }

    @Override
    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advised.isProxyTargetClass()) {
            return new Cglib2AopProxy(advised);
        }
        return new JdkDynamicAopProxy(advised);
    }
}
